package common

import (
	"os"
	"os/exec"
	"path/filepath"

	"github.com/astaxie/beego/logs"
	"github.com/gogf/gf/os/gcache"
)

type CommonLogger = logs.BeeLogger
type CommonCache = gcache.Cache

var (
	BLogger *CommonLogger
	BCache  *CommonCache
)

func init() {
	//注册服务的时候,运行上下文环境会改变,切换目录.
	workRoot, _ := exec.LookPath(os.Args[0])
	err := os.Chdir(filepath.Dir(workRoot))
	if err != nil {
		panic(err)
	}
	// beego log框架自带
	BLogger = logs.NewLogger(1000)
	BLogger.SetLogger(logs.AdapterFile, `{"filename":"Monitor.log","level":7}`)
	BLogger.SetLevel(logs.LevelDebug) // 设置日志写入缓冲区的等级
	BLogger.EnableFuncCallDepth(true) // 输出log时能显示输出文件名和行号(非必须)
	BCache = gcache.New()
}
